<?php


namespace Module\File\Admin\Controller;


use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;
use ModStart\Grid\GridFilter;
use ModStart\Support\Concern\HasFields;
use Module\File\Model\File;
use Module\File\Model\FileCategory;

class FileController extends Controller
{
    use HasAdminQuickCRUD;

    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder
            ->init(File::class)
            ->field(function ($builder) {
                /** @var HasFields $builder */
                $builder->id('id', 'ID');
                $builder->select('categoryId', '分类')->optionModelTree(FileCategory::class);
                $builder->text('name', '文件名称');
                $builder->file('file', '文件');
                $builder->richHtml('content', '内容')->listable(false);
                $builder->text('userId','用户姓名');
                $builder->display('created_at', L('Created At'))->listable(false);
                $builder->display('updated_at', L('Updated At'))->listable(false);
            })
            ->gridFilter(function (GridFilter $filter) {
                $filter->eq('id', L('ID'));
                $filter->like('title', L('Title'));
            })
            ->title('文件管理列表')
            ->defaultOrder(['sort', 'asc'])
            ->canSort(true);
    }
}
